// @ts-nocheck
import router from '@system.router';
import list from '../../common/mock/cookbook-list.json'

export default {
  // 如果要去收取上个页面路由传递过来的参数，
  // data option 必须定义，哪怕是空值
  data: {
    list: [],
    refreshing: false,
    currentPage: 1,
    pageSize: 10,
    loadMoreText: '加载中...'
  },

  enterkeyClick() {

  },

  change() {

  },

  handleBackClick() {
    router.back()
  },

  onReady() {
    console.log(this.title)
  },

  // 自定义函数
  // list [10] [20] [30]
  // list [10]
  loadData() {
    this.list = list.data.slice(0, this.currentPage * this.pageSize)
  },

  handleRefresh(refreshing) {
//    console.log(JSON.stringify(refreshing.refreshing))
    this.refreshing = true
    setTimeout(() => {
      this.currentPage = 1
      this.loadData()
      this.refreshing = false
    }, 2000)
  },

  onInit() {
    this.loadData()
    this.totalPage = Math.ceil(list.data.length / this.pageSize)
  },

  handlePulldown({state}) {

  },

  handleScrollBottom() {
    setTimeout(() => {
      this.currentPage++
      if (this.currentPage <= this.totalPage) {
        this.loadData()
      } else {
        this.loadMoreText = '到底了~'
      }
    }, 500)
  },

  handleItemClick($item) {
    router.push({
      uri: 'pages/detail/detail',
      params: $item
    })
  }
}